package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r:= gin.Default()
	// 路由组1 ，处理GET请求
	v1 := r.Group("/v1")
	//
	{
		v1.GET("login",login)
		v1.GET("submit", submit)
	}
	v2 := r.Group("/V2")
	{
		v2.POST("login",login)
		v2.POST("submit", submit)
	}
	r.GET("/topgoer",heelloHandler)
	if err := r.Run();err !=nil {
		fmt.Println("startup service failed, err:%v\n", err)
	}


	r.Run(":8500")
}
func login (c *gin.Context)	{
	name := c.DefaultQuery("name","jack")
	c.String(http.StatusOK, fmt.Sprintf("hello %s\n", name))
}
func submit(c *gin.Context)  {
	name := c.DefaultQuery("name", "lily")
	c.String(http.StatusOK, fmt.Sprintf("hello %s\n", name))
}

//基础路由
func heelloHandler(c*gin.Context){
	c.JSON(http.StatusOK,gin.H{
		"message": "Hello www.topgoer.com!",
	})
}

